package com.qf.exception;

import com.qf.entity.base.BusinessException;
import com.qf.entity.base.ResultEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description:
 * @Author: xbb
 * @Date:2020/4/14
 */
@ControllerAdvice   //全局异常
public class globalExceptionHandler {

    //处理系统异常
    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResultEntity systemEx(Exception e){
        e.printStackTrace();
        return ResultEntity.error(e.getMessage());
    }

    //处理业务异常
    @ExceptionHandler(value = BusinessException.class)
    @ResponseBody
    public ResultEntity businessEx(BusinessException e){
        System.out.println("业务异常"+e.getMessage());
        return ResultEntity.error(e.getMsg());
    }
}
